package com.atlassian.confluence.plugin.example.listener;
 
import com.atlassian.confluence.event.events.security.LoginEvent;
import com.atlassian.confluence.event.events.security.LogoutEvent;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
 
public class AnnotatedListener implements DisposableBean{
    private static final Logger log = LoggerFactory.getLogger(AnnotatedListener.class);
 
    protected EventPublisher eventPublisher;
 
    public AnnotatedListener(EventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
        eventPublisher.register(this);
    }
 
 	// Change the following event handlers to listen for
 	// IssueCreate, WorkStart, WorkStop, IssueClose events
    @EventListener
    public void loginEvent(LoginEvent event) {
        log.error("Login Event: " + event);
    }
 
    @EventListener
    public void logoutEvent(LogoutEvent event) {
        log.error("Logout Event: " + event);
    }
 
    // Unregister the listener if the plugin is uninstalled or disabled.
    public void destroy() throws Exception
    {
        eventPublisher.unregister(this);
    }
}